package com.woniuxy.hrp.service.Serviceimpl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.woniuxy.hrp.Vo.MrecordPage;
import com.woniuxy.hrp.entity.Mrecord;
import com.woniuxy.hrp.entity.PageBean;
import com.woniuxy.hrp.mapper.MrecordMapper;
import com.woniuxy.hrp.service.MrecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service("mrecordService")
public class MrecordServiceImp implements MrecordService {
    @Autowired
    private MrecordMapper mrecordMapper;

    @Override
    public void add(Mrecord mrecord) {
        /**
         * @Author  李国杰
         * @Description //添加就诊记录
         * @Date 9:55 2022/8/30
         * @Param [mrecord]
         * @return void
         **/
        mrecordMapper.insert(mrecord);
    }

    @Override
    public List<Mrecord> seleByCo(Mrecord mrecord) {
        /**
         * @Author  李国杰
         * @Description //按条件去查询
         * @Date 9:55 2022/8/30
         * @Param [mrecord]
         * @return java.util.List<com.woniuxy.hrp.entity.Mrecord>
         **/
    return mrecordMapper.seleByCon(mrecord);
    }

    /**
     * 根据病人id获取该病人的所有就诊记录
     * @param PatientId
     * @return
     */
    @Override
    public List<Mrecord> seleByPatientId(int PatientId) {
        //增加缓存
        List<Mrecord> mrecords = mrecordMapper.seleByPatientId(PatientId);
        return mrecords;
    }

    /**
     * 根据就诊id获取检查
     * @param mrecordId
     * @return
     */
    @Override
    public Mrecord seleMrecordByMrecordId(int mrecordId) {
        Mrecord mrecord = mrecordMapper.seleByMrecordId(mrecordId);
        return mrecord;
    }

    /**
     * 根据患者id查询就诊记录并实现分页
     * @param mrecordPage
     * @return
     */
    @Override
    public PageBean<Mrecord> seleMrecordByPatientId1(MrecordPage mrecordPage) {
        int pageSize=5;
        if(mrecordPage.getPageSize()!=0){
            pageSize=mrecordPage.getPageSize();
        }
        PageBean<Mrecord> pageBean = new PageBean<>();
        Page page = PageHelper.startPage(mrecordPage.getPage(), pageSize);
        List<Mrecord> mrecords = mrecordMapper.seleByPatientId(mrecordPage.getPatientId());
        pageBean.setData(mrecords);//将查询的数据放到pagebean中
        pageBean.setCurrPage(mrecordPage.getPage());//设置当前展示是哪页
        pageBean.setCurrPageSize(mrecords.size());
        pageBean.setPageSize(pageSize);
        pageBean.setTotalPages((int)page.getTotal());//PageHelper分出的总条数
        pageBean.setTotalPages(page.getPages());//PageHelper获取的总页数
        return pageBean;
    }

}
